from selenium.webdriver.common.by import By


from util.Util import BoxDriver,BasePage

from service.login import Login


class Adduser(BasePage):

    def dingwei(self):
        # 定位后台管理
        self.driver.click(By.XPATH,'//*[@id="s-menu-superadmin"]/button')
        self.driver.switch_to_frame_index(0)
        # 点击添加成员


    def adduser(self,*args):
        # 传值顺序 account, realname, gender, dept, role, passwd1, passwd2, email
        # 添加成员
        self.driver.click(By.LINK_TEXT, '添加成员')
        self.driver.input(By.ID, "account",args[0])
        self.driver.input(By.ID, "realname",args[1])
        self.driver.click(By.ID, args[2])

        self.driver.select_by_index(By.ID, "dept",args[3])
        self.driver.select_by_index(By.ID, "role",args[4])

        self.driver.input(By.ID, "password1",args[5])
        self.driver.input(By.ID, "password2",args[6])
        self.driver.input(By.ID, "email",args[7])
        self.driver.click(By.ID, "submit")

    def getlastname(self):
        # 通过账号进行断言操作
        # 点到尾页 获取最后一个
        input = self.driver.input(By.ID, "_pageID", 1000)
        if input == "":
            return ""
        self.driver.click(By.ID, "goto")
        # 获取元素
        realname = self.driver.find_elements(By.XPATH, "/html/body/div/div/div/div[2]/div/div/table/tbody/tr/td[2]")
        if len(realname) > 0:
            return self.driver.find_elements(By.XPATH, "/html/body/div/div/div/div[2]/div/div/table/tbody/tr/td[2]")[-1].text
        else:
            return ""

    def assertuser(self,account):
        # 通过账号进行断言操作
        assert self.getlastname() == account

    # def localaddu(self):
    #     # 定位到添加用户
    #     self.driver.click(By.LINK_TEXT,"添加用户")


if __name__ == '__main__':
    driver = BoxDriver('Chrome')
    Login(driver).login('admin', '123456')

    Adduser(driver).adduser("zhaoliu","zhaoliu","genderm",2,2,"111111","111111","111@qq.com")
